package com.zj.leetcode.easy.hash;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * @program: algorithm
 * @description:
 * 键盘行
 * 500 keyboard-row
 * @author: Zhang Bo
 * @create: 2022-01-14 17:05
 **/
public class KeyboardRow{
    public static void main(String[] args) {
        Solution solution = new KeyboardRow().new Solution();
        solution.generate();
//        solution.findWords(new String[1]);
    }
    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {

        public String[] findWords(String[] words) {
            HashMap<Character, Integer> map = new HashMap<Character, Integer>();
            map.put('q', 0);
            map.put('w', 0);
            map.put('e', 0);
            map.put('r', 0);
            map.put('t', 0);
            map.put('y', 0);
            map.put('u', 0);
            map.put('i', 0);
            map.put('o', 0);
            map.put('p', 0);
            map.put('a', 1);
            map.put('s', 1);
            map.put('d', 1);
            map.put('f', 1);
            map.put('g', 1);
            map.put('h', 1);
            map.put('j', 1);
            map.put('k', 1);
            map.put('l', 1);
            map.put('z', 2);
            map.put('x', 2);
            map.put('c', 2);
            map.put('v', 2);
            map.put('b', 2);
            map.put('n', 2);
            map.put('m', 2);


            ArrayList<String> list = new ArrayList<>();
            for (int i = 0; i < words.length; i++) {
                int line = -1;
                boolean flag = true;
                for (int j = 0; j < words[i].length(); j++) {
                    char key = Character.toLowerCase(words[i].charAt(j));

                    if(line != -1 && map.get(key) != line){
                        flag = false;
                        break;
                    }
                    line = map.get(key);
                }
                if(flag){
                    list.add(words[i]);
                }
            }

            return list.toArray(new String[list.size()]);
        }


        public void generate(){
            for (char c : "qwertyuiop".toCharArray()) {
                System.out.println("map.put('" + c + "', 0);");
            }

            for (char c : "asdfghjkl".toCharArray()) {
                System.out.println("map.put('" + c + "', 1);");
            }

            for (char c : "zxcvbnm".toCharArray()) {
                System.out.println("map.put('" + c + "', 2);");
            }
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}
